﻿using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SGH
{
    /// <summary>
    /// 排序，返回最小或最大值
    /// </summary>
    class Method
    {
        //排序
        public static int getMax(List<int[]> set)
        {
            int n = set.Count;
            int[] demanNum = new int[n];
            for (int i = 0; i < n; i++)
            {
                demanNum[i] = set[i][1];
            }
            int[] newSet = bubbleSort(demanNum);
            return newSet[n - 1];
        }

        public static int getMax(int[] set)
        {
            int[] newSet = bubbleSort(set);
            int n=newSet.Length;
            return set[n - 1];
        }

        public static int getMin(int[] set)
        {
            int[] newSet = bubbleSort(set);
            return newSet[0];
        }

        public static double getMax(double[] set)
        {
            double[] newSet = bubbleSort(set);
            int n = newSet.Length;
            return set[n - 1];
        }

        public static double getMin(double[] set)
        {
            double[] newSet = bubbleSort(set);
            return newSet[0];
        }

        public static int[] getSortedSet(int[] set)
        {
            return bubbleSort(set);
        }

        public static double[] getSortedSet(double[] set)
        {
            return bubbleSort(set);
        }

        private static int[] bubbleSort(int[] set)
        {
            int n = set.Length;
            var tempSet = new int[n];
            for (int i = 0; i < n; i++)
            {
                tempSet[i] = set[i];
            }
            int temp;
            for (int i = 0; i < n; i++)
            {
                for (int j = i + 1; j < n; j++)
                {
                    if (tempSet[i] > tempSet[j])
                    {
                        temp = tempSet[j];
                        tempSet[j] = tempSet[i];
                        tempSet[i] = temp;
                    }
                }
            }
            return tempSet;
        }

        private static double[] bubbleSort(double[] tempSet)
        {
            int n = tempSet.Length;
            var set = new double[n];
            for (int i = 0; i < n; i++)
            {
                set[i] = tempSet[i];
            }
            double temp;
            for (int i = 0; i < n; i++)
            {
                for (int j = i + 1; j < n; j++)
                {
                    if (set[i] > set[j])
                    {
                        temp = set[j];
                        set[j] = set[i];
                        set[i] = temp;
                    }
                }
            }
            return set;
        }
    }
}
